package com.xdcplus.web.controller.wip;


import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import com.xdcplus.exceptions.domain.ResponseVO;
import com.xdcplus.mom.controller.AbstractController;
import com.xdcplus.pager.vo.PageVO;
import com.xdcplus.web.common.pojo.dto.wip.WipUnpackPlanDTO;
import com.xdcplus.web.common.pojo.dto.wip.WipUnpackPlanFilterDTO;
import com.xdcplus.web.common.pojo.entity.wip.WipUnpackPlan;
import com.xdcplus.web.common.pojo.vo.wip.WipUnpackPlanVO;
import com.xdcplus.web.service.wip.WipUnpackPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;


/**
 * 投料/拆包计划表(WipUnpackPlan)表服务控制层
 *
 * @author xyy
 * @since 2023-05-04 19:55:25
 */
@Api(tags = "拆包计划表(WipUnpackPlan)")
@Slf4j
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("wipUnpackPlan")
public class WipUnpackPlanController extends AbstractController {

    @Autowired
    private WipUnpackPlanService wipUnpackPlanService;

    @ApiOperation("新增拆包计划表")
    @PostMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<WipUnpackPlan> saveWipUnpackPlan(@RequestBody WipUnpackPlanDTO wipUnpackPlanDTO) {

        log.info("saveWipUnpackPlan {}", wipUnpackPlanDTO.toString());
        wipUnpackPlanDTO.setCreatedUser(getAccount());
        return ResponseVO.success(wipUnpackPlanService.saveWipUnpackPlan(wipUnpackPlanDTO));
    }

    @ApiOperation("修改拆包计划表")
    @PutMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO updateWipUnpackPlan(@RequestBody WipUnpackPlanDTO wipUnpackPlanDTO) {

        log.info("updateWipUnpackPlan {}", wipUnpackPlanDTO.toString());

        wipUnpackPlanDTO.setUpdatedUser(getAccount());
        wipUnpackPlanService.updateWipUnpackPlan(wipUnpackPlanDTO);

        return ResponseVO.success();
    }

    @ApiOperation("计划下达")
    @PutMapping(value = "/command", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO commandWipUnpackPlan(@RequestBody List<Long> wipUnpackPlanIds) {
        log.info("commandWipUnpackPlan {}", wipUnpackPlanIds.toString());
        wipUnpackPlanService.commandWipUnpackPlan(wipUnpackPlanIds,getAccount());
        return ResponseVO.success();
    }

    @ApiOperation("结束计划")
    @PutMapping(value = "/canel", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO canelWipUnpackPlan(@RequestBody List<Long> wipUnpackPlanIds) {
        log.info("commandWipUnpackPlan {}", wipUnpackPlanIds.toString());
        wipUnpackPlanService.canelWipUnpackPlan(wipUnpackPlanIds,getAccount());
        return ResponseVO.success();
    }

//    @ApiOperation("取消拆包计划表")
//    @PutMapping(value = "/cancelWipUnpackPlan/{wipUnpackPlanId}", produces = MediaType.APPLICATION_JSON_VALUE)
//    @ApiImplicitParams({
//            @ApiImplicitParam(paramType = "path", name = "wipUnpackPlanId", dataTypeClass = Long.class, value = "投料/拆包计划表ID", required = true),
//    })
//    public ResponseVO cancelWipUnpackPlan(@PathVariable("wipUnpackPlanId")
//                                                 @NotNull(message = "投料/拆包计划表ID不能为空") Long wipUnpackPlanId) {
//
//        log.info("cancelWipUnpackPlan {}", wipUnpackPlanId);
//        wipUnpackPlanService.cancelWipUnpackPlan(wipUnpackPlanId,getAccount());
//
//        return ResponseVO.success();
//    }

    @ApiOperation("删除拆包计划表")
    @DeleteMapping(value = "/{wipUnpackPlanId}", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "wipUnpackPlanId", dataTypeClass = Long.class, value = "投料/拆包计划表ID", required = true),
    })
    public ResponseVO deleteWipUnpackPlanLogical(@PathVariable("wipUnpackPlanId")
                                         @NotNull(message = "投料/拆包计划表ID不能为空") Long wipUnpackPlanId) {

        log.info("deleteWipUnpackPlanLogical {}", wipUnpackPlanId);

        wipUnpackPlanService.deleteWipUnpackPlanLogical(wipUnpackPlanId);

        return ResponseVO.success();
    }

    @ApiOperation("批量删除拆包计划表")
    @DeleteMapping(value = "/deleteBatch", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "wipUnpackPlanId", dataTypeClass = Long.class, value = "投料/拆包计划表ID", required = true),
    })
    public ResponseVO deleteBatchWipUnpackPlanLogical(@RequestBody List<Long> wipUnpackPlanIds) {

        log.info("deleteBatchWipUnpackPlanLogical {}", wipUnpackPlanIds);
        Assert.isTrue(ObjectUtil.isNotEmpty(wipUnpackPlanIds),"计划id不能为空");
        wipUnpackPlanService.deleteBatchWipUnpackPlanLogical(wipUnpackPlanIds);
        return ResponseVO.success();
    }

    @ApiOperation("查询拆包计划表")
    @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<PageVO<WipUnpackPlanVO>> findWipUnpackPlan(WipUnpackPlanFilterDTO wipUnpackPlanFilterDTO) {
        log.info("findWipUnpackPlan {}", wipUnpackPlanFilterDTO);
        return ResponseVO.success(wipUnpackPlanService.queryWipUnpackPlan(wipUnpackPlanFilterDTO));
    }



}
